﻿using PermissionManager.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace PermissionsManager.Models
{
    public class LoginAuthorizeAttribute: AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            //判断是否跳过授权过滤器
            if (filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true)
               || filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true))
            {
                return;
            }

            //判断登录情况
            if (AdminUserContext.context.UserInfo_no == null)
            {
                //filterContext.Result = new RedirectResult("/Login/Login");
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary{ { "Controller","Login"},
                    { "Action","Login"},
                    { "ReturnUrl",filterContext.HttpContext.Request.Path}
                });

            }
        }
    }
}